package com.yiren.manager.ctrl.cost;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.w3c.dom.ls.LSInput;

import com.github.pagehelper.StringUtil;
import com.yiren.core.exception.MyException;
import com.yiren.core.form.GenericForm;
import com.yiren.core.repository.utils.QueryResult;
import com.yiren.core.utils.HTTPResult;
import com.yiren.entity.YrBeHospitalPledge;
import com.yiren.entity.YrBed;
import com.yiren.entity.YrElder;
import com.yiren.entity.YrElderArrearage;
import com.yiren.entity.YrElderBeHospital;
import com.yiren.entity.YrElderPayRecord;
import com.yiren.entity.YrElderWallet;
import com.yiren.entity.YrElderWalletRechargeRecord;
import com.yiren.entity.YrMealCard;
import com.yiren.entity.YrOutFeeRecord;
import com.yiren.entity.YrStaffInfo;
import com.yiren.entity.YrUserVipCard;
import com.yiren.entity.YrWalletReturn;
import com.yiren.manager.ctrl.GenericController;
import com.yiren.manager.form.cost.YrElderArrearageForm;
import com.yiren.manager.form.cost.YrElderCostInventoryForm;
import com.yiren.manager.form.cost.YrElderPayRecordForm;
import com.yiren.manager.form.cost.YrOutFeeRecordForm;
import com.yiren.manager.form.elder.YrElderBeHospitalForm;
import com.yiren.manager.form.elder.YrElderForm;
import com.yiren.manager.form.elder.YrElderWalletForm;
import com.yiren.manager.form.messhall.YrMealCardForm;
import com.yiren.manager.service.iface.beds.YrBedService;
import com.yiren.manager.service.iface.cost.YrElderArrearageService;
import com.yiren.manager.service.iface.cost.YrElderPayRecordService;
import com.yiren.manager.service.iface.cost.YrElderWalletRechargeRecordService;
import com.yiren.manager.service.iface.cost.YrOutFeeRecordService;
import com.yiren.manager.service.iface.department.YrStaffInfoService;
import com.yiren.manager.service.iface.elder.YrElderBeHospitalService;
import com.yiren.manager.service.iface.elder.YrElderService;
import com.yiren.manager.service.iface.elder.YrElderWalletService;
import com.yiren.manager.service.iface.elder.YrWalletReturnService;
import com.yiren.manager.service.iface.lease.YrBeHospitalPledgeService;
import com.yiren.manager.service.iface.messhall.YrMealCardService;
import com.yiren.manager.service.iface.vip.YrUserVipCardService;
import com.yiren.manager.utils.ObjectUtils;

@RequestMapping("elderPayRecord")
@Controller
public class YrElderPayRecordController extends GenericController<YrElderPayRecordForm, YrElderPayRecord> {

	@Autowired
	private YrElderPayRecordService selfService;

	@Autowired
	private YrElderBeHospitalService elderBeHospitalService;

	@Autowired
	private YrElderService elderService;

	@Autowired
	private YrStaffInfoService staffInfoService;

	@Autowired
	private YrElderPayRecordService elderPayRecordService;

	@Autowired
	private YrElderArrearageService elderArrearageService;

	@Autowired
	private YrElderWalletRechargeRecordService elderWalletRechargeRecordService;

	@Autowired
	private YrElderWalletService elderWalletService;

	@Autowired
	private YrWalletReturnService walletReturnService;

	@Autowired
	private YrBeHospitalPledgeService beHospitalPledgeService;

	@Autowired
	private YrOutFeeRecordService outFeeRecordService;

	@Autowired
	private YrMealCardService mealCardService;

	@Autowired
	private YrUserVipCardService userVipCardService;

	@Autowired
	private YrBedService bedService;

	@RequestMapping("findByDate")
	@ResponseBody
	public HTTPResult<YrElderPayRecordForm> findByDate(String dateSince, String dateEnd, String searchVal)
			throws Exception {
		HTTPResult<YrElderPayRecordForm> result = new HTTPResult<YrElderPayRecordForm>();
		if (searchVal == null || dateSince == null || dateEnd == null) {
			throwExp("参数有误");
		}
		String sqlWhere = "DATE_FORMAT(pay_date,'%Y-%m-%d') >= ?1 AND DATE_FORMAT(pay_date,'%Y-%m-%d')<=?2 AND (elder_name=?3 OR elder_card_id=?4) AND pay_status=1";
		LinkedHashMap<String, String> sortMap = new LinkedHashMap<>();
		sortMap.put("createTime", "DESC");

		QueryResult<YrElderPayRecord> qr = selfService.find(YrElderPayRecord.class, sqlWhere,
				new Object[] { dateSince, dateEnd, searchVal, searchVal }, sortMap);

		List<YrElderPayRecordForm> formList = new ArrayList<YrElderPayRecordForm>();
		for (YrElderPayRecord entity : qr.getResultList()) {
			formList.add(toForm(entity));
		}
		result.setData(formList);

		return result;
	}

	@RequestMapping("findDayInventory")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findDayInventory(String day, String beHospitalId) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (day == null || beHospitalId == null) {
			throwExp("参数有误");
		}

		result.setData(findInventory(1, day, beHospitalId));
		return result;
	}

	@RequestMapping("findMonthInventory")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findMonthInventory(String month, String beHospitalId)
			throws MyException, InstantiationException, IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (month == null || beHospitalId == null) {
			throwExp("参数有误");
		}

		result.setData(findInventory(2, month, beHospitalId));
		return result;
	}

	@RequestMapping("findDayInventoryColl")
	@ResponseBody
	public HTTPResult<InventoryCollForm> findDayInventoryColl(String day, String beHospitalId) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		HTTPResult<InventoryCollForm> result = new HTTPResult<InventoryCollForm>();
		if (day == null || beHospitalId == null) {
			throwExp("参数有误");
		}

		List<YrElderCostInventoryForm> elderCostInventoryForms = findInventory(1, day, beHospitalId);

		if (elderCostInventoryForms.isEmpty()) {
			throwExp("汇总数据出错");
		}

		result.setData(costInventoryColl(elderCostInventoryForms));
		return result;
	}

	@RequestMapping("findMonthInventoryColl")
	@ResponseBody
	public HTTPResult<InventoryCollForm> findMonthInventoryColl(String month, String beHospitalId) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		HTTPResult<InventoryCollForm> result = new HTTPResult<InventoryCollForm>();
		if (month == null || beHospitalId == null) {
			throwExp("参数有误");
		}

		List<YrElderCostInventoryForm> elderCostInventoryForms = findInventory(2, month, beHospitalId);

		if (elderCostInventoryForms.isEmpty()) {
			throwExp("汇总数据出错");
		}

		result.setData(costInventoryColl(elderCostInventoryForms));
		return result;
	}

	public List<InventoryCollForm> costInventoryColl(List<YrElderCostInventoryForm> elderCostInventoryForms) {
		List<InventoryCollForm> inventoryCollFroms = new ArrayList<>();
		for (YrElderCostInventoryForm elderCostInventoryForm : elderCostInventoryForms) {
			InventoryCollForm inventoryCollFrom = new InventoryCollForm();
			inventoryCollFrom.setElderBeHospitalForm(elderCostInventoryForm.getElderBeHospitalForm());

			Map<String, ArreaForm> mapArrea = new HashMap<>();
			for (YrElderArrearageForm arrearageForm : elderCostInventoryForm.getElderArrearageForms()) {
				ArreaForm arreaForm = mapArrea.get(arrearageForm.getArrearageDesc());
				if (mapArrea.containsKey(arrearageForm.getArrearageDesc())) {
					arreaForm.setCount(arreaForm.getCount() == null ? 1 : arreaForm.getCount() + 1);
					arreaForm.setTotalArreaMoney(
							arreaForm.getTotalArreaMoney() == null ? arrearageForm.getArrearageMoney()
									: arreaForm.getTotalArreaMoney() + arrearageForm.getArrearageMoney());
				} else {
					arreaForm = new ArreaForm();
					arreaForm.setCount(1);
					arreaForm.setTotalArreaMoney(arrearageForm.getArrearageMoney());
					arreaForm.setArreaDesc(arrearageForm.getArrearageDesc());
				}
				mapArrea.put(arrearageForm.getArrearageDesc(), arreaForm);
			}

			Map<String, PayRecordFrom> mapPayRecord = new HashMap<>();
			for (YrElderPayRecordForm payRecordForm : elderCostInventoryForm.getElderPayRecordForms()) {
				PayRecordFrom payFrom = mapPayRecord.get(payRecordForm.getCostDesc());
				if (mapPayRecord.containsKey(payRecordForm.getCostDesc())) {
					payFrom.setCount(payFrom.getCount() == null ? 1 : payFrom.getCount() + 1);
					payFrom.setTotalPayMoney(payFrom.getTotalPayMoney() == null ? payRecordForm.getPayMoney()
							: payFrom.getTotalPayMoney() + payRecordForm.getPayMoney());
				} else {
					payFrom = new PayRecordFrom();
					payFrom.setCount(1);
					payFrom.setTotalPayMoney(payRecordForm.getPayMoney());
					payFrom.setPayDesc(payRecordForm.getCostDesc());
				}
				mapPayRecord.put(payRecordForm.getCostDesc(), payFrom);
			}

			List<ArreaForm> arreaForms = new ArrayList<>();
			for (Map.Entry<String, ArreaForm> entryArrea : mapArrea.entrySet()) {
				arreaForms.add(entryArrea.getValue());
			}
			List<PayRecordFrom> payRecordFroms = new ArrayList<>();
			for (Map.Entry<String, PayRecordFrom> entryPayReocrd : mapPayRecord.entrySet()) {
				payRecordFroms.add(entryPayReocrd.getValue());
			}
			inventoryCollFrom.setArreaForms(arreaForms);
			inventoryCollFrom.setPayRecordFroms(payRecordFroms);
			inventoryCollFroms.add(inventoryCollFrom);
		}

		return inventoryCollFroms;
	}

	private class InventoryCollForm extends GenericForm {
		private YrElderBeHospitalForm elderBeHospitalForm;
		private List<ArreaForm> arreaForms;
		private List<PayRecordFrom> payRecordFroms;

		public YrElderBeHospitalForm getElderBeHospitalForm() {
			return elderBeHospitalForm;
		}

		public void setElderBeHospitalForm(YrElderBeHospitalForm elderBeHospitalForm) {
			this.elderBeHospitalForm = elderBeHospitalForm;
		}

		public List<ArreaForm> getArreaForms() {
			return arreaForms;
		}

		public void setArreaForms(List<ArreaForm> arreaForms) {
			this.arreaForms = arreaForms;
		}

		public List<PayRecordFrom> getPayRecordFroms() {
			return payRecordFroms;
		}

		public void setPayRecordFroms(List<PayRecordFrom> payRecordFroms) {
			this.payRecordFroms = payRecordFroms;
		}

	}

	private class ArreaForm {
		private String arreaDesc;
		private Integer count;
		private Float totalArreaMoney;

		public String getArreaDesc() {
			return arreaDesc;
		}

		public void setArreaDesc(String arreaDesc) {
			this.arreaDesc = arreaDesc;
		}

		public Integer getCount() {
			return count;
		}

		public void setCount(Integer count) {
			this.count = count;
		}

		public Float getTotalArreaMoney() {
			return totalArreaMoney;
		}

		public void setTotalArreaMoney(Float totalArreaMoney) {
			this.totalArreaMoney = totalArreaMoney;
		}
	}

	private class PayRecordFrom {

		private String payDesc;
		private Integer count;
		private Float totalPayMoney;

		public String getPayDesc() {
			return payDesc;
		}

		public void setPayDesc(String payDesc) {
			this.payDesc = payDesc;
		}

		public Integer getCount() {
			return count;
		}

		public void setCount(Integer count) {
			this.count = count;
		}

		public Float getTotalPayMoney() {
			return totalPayMoney;
		}

		public void setTotalPayMoney(Float totalPayMoney) {
			this.totalPayMoney = totalPayMoney;
		}
	}

	/**
	 * 
	 * @param findType
	 *            查找类型 1按日 2按月
	 * @param findVal
	 * @param beHospitalId
	 * @return
	 * @throws MyException
	 * @throws InvocationTargetException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	private List<YrElderCostInventoryForm> findInventory(Integer findType, String findVal, String beHospitalId)
			throws MyException, InstantiationException, IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		String findFormat = null;
		if (findType == 1) {
			findFormat = "\'%Y-%m-%d\'";
		} else {
			findFormat = "\'%Y-%m\'";
		}

		YrElderBeHospital elderBeHospital = elderBeHospitalService.findOne(beHospitalId);
		if (elderBeHospital == null) {
			throwExp("查询不到该老者入院登记信息");
		}
		YrElder elder = elderService.findOne(elderBeHospital.getElderId());
		if (elder == null) {
			throwExp("查询不到相关老者信息");
		}
		YrElderBeHospitalForm beHospitalForm = ObjectUtils.objectToObject(elderBeHospital, YrElderBeHospitalForm.class);
		beHospitalForm.setElderForm(ObjectUtils.objectToObject(elder, YrElderForm.class));

		YrBed bed = bedService.findOne(elderBeHospital.getBedId());
		if (null != bed) {
			beHospitalForm.setBedNumber(bed.getBedNumber());
		}
		String sqlWhere = "subject_room_id=?1 AND manager_of_subject_room=1 AND status=0";

		QueryResult<YrStaffInfo> qrStaffInfo = staffInfoService.find(YrStaffInfo.class, sqlWhere,
				new Object[] { elderBeHospital.getSubjectRoomId() });
		if (qrStaffInfo.getTotalRecord() > 0) {
			beHospitalForm.setSubjectRoomManager(qrStaffInfo.getResultList().get(0).getName());
		}
		// sqlWhere = "elder_id=?1 AND be_hospital_id=?3 AND
		// ((DATE_FORMAT(pay_date," + findFormat
		// + ")=?2 AND cost_type<>12) OR (cost_type=12 AND "
		// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId),"
		// + findFormat + ")=?2 AND (SELECT t.beHospitalId FROM YrElderArrearage
		// t WHERE t.elderArrearageId = o.relationId)=?3)) ";

		sqlWhere = "elder_id=?1 AND be_hospital_id=?3 AND DATE_FORMAT(pay_date," + findFormat + ")=?2";
		List<YrElderPayRecordForm> elderPayRecordForms = getElderPayRecordForms(sqlWhere,
				new Object[] { elder.getElderId(), findVal, beHospitalId });

		sqlWhere = "elder_id=?1 AND DATE_FORMAT(should_pay_date," + findFormat
				+ ") = ?2 AND status=0 AND be_hospital_id=?3";
		List<YrElderArrearageForm> elderArrearageForms = getElderArrearageForms(sqlWhere,
				new Object[] { elder.getElderId(), findVal, beHospitalId });

		YrElderCostInventoryForm form = new YrElderCostInventoryForm();
		sqlWhere = "be_hospital_id=?1";
		YrOutFeeRecord outFeeRecord = null;
		QueryResult<YrOutFeeRecord> qrOutFeeRecord = outFeeRecordService.find(YrOutFeeRecord.class, sqlWhere,
				new Object[] { elderBeHospital.getBeHospitalId() });
		if (!qrOutFeeRecord.getResultList().isEmpty()) {
			outFeeRecord = qrOutFeeRecord.getResultList().get(0);
			YrOutFeeRecordForm outFeeRecordForm = ObjectUtils.objectToObject(outFeeRecord, YrOutFeeRecordForm.class);
			form.setOutFeeRecordForm(outFeeRecordForm);
		}

		sqlWhere = "elder_id=?1";
		QueryResult<YrElderWallet> qrElderWallet = elderWalletService.find(YrElderWallet.class, sqlWhere,
				new Object[] { elder.getElderId() });
		if (!qrElderWallet.getResultList().isEmpty()) {
			YrElderWalletForm elderWalletForm = ObjectUtils.objectToObject(qrElderWallet.getResultList().get(0),
					YrElderWalletForm.class);
			form.setElderWalletForm(elderWalletForm);
		}

		sqlWhere = "card_person_id=?1";
		QueryResult<YrMealCard> qrMealCard = mealCardService.find(YrMealCard.class, sqlWhere,
				new Object[] { elder.getElderId() });

		if (!qrMealCard.getResultList().isEmpty()) {
			YrMealCard mealCard = qrMealCard.getResultList().get(0);
			YrMealCardForm mealCardForm = ObjectUtils.objectToObject(mealCard, YrMealCardForm.class);
			form.setMealCardForm(mealCardForm);
		}

		// 查询出所有的预交款
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2";
		QueryResult<YrElderWalletRechargeRecord> reQueryResult = elderWalletRechargeRecordService
				.find(YrElderWalletRechargeRecord.class, sqlWhere, new Object[] { elder.getElderId(), beHospitalId });

		Float prePay = 0F;
		for (YrElderWalletRechargeRecord rechargeRecord : reQueryResult.getResultList()) {
			prePay += rechargeRecord.getRechargeMoney();
		}
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2 AND pay_way<>3";// 除去VIP卡
		Float totalFee = 0F;
		// 查询出所有的费用
		QueryResult<YrElderPayRecord> qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
			totalFee += elderPayRecord.getPayMoney();
		}
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2 AND source=1";
		// 查询出返回钱包的钱
		QueryResult<YrWalletReturn> qrWallerReturn = walletReturnService.find(YrWalletReturn.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		Float returnMoney = 0F;

		for (YrWalletReturn walletReturn : qrWallerReturn.getResultList()) {
			returnMoney += walletReturn.getReturnMoney();
		}
		sqlWhere = "status=0 AND be_hospital_id=?1";
		QueryResult<YrBeHospitalPledge> qrBeHospitalPledge = beHospitalPledgeService.find(YrBeHospitalPledge.class,
				sqlWhere, new Object[] { beHospitalId });
		Float pledge = 0F;
		for (YrBeHospitalPledge beHospitalPledge : qrBeHospitalPledge.getResultList()) {
			pledge += beHospitalPledge.getPledge();
		}
		form.setPledge(pledge);
		form.setElderBeHospitalForm(beHospitalForm);
		form.setElderArrearageForms(elderArrearageForms);
		form.setElderPayRecordForms(elderPayRecordForms);
		form.setPrePay(prePay);
		form.setTotalFee(totalFee);
		form.setReturnMoney(returnMoney);

		List<YrElderCostInventoryForm> formList = new ArrayList<YrElderCostInventoryForm>();
		formList.add(form);

		return formList;
	}

	@RequestMapping("findInventoryBySearchVal")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findCostInventory(String searchVal, String month) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (searchVal == null || month == null) {
			throwExp("参数有误");
		}
		String sqlWhere = "name=?1 OR elder_id=?2 OR card_id=?3";

		QueryResult<YrElder> qrElder = elderService.find(YrElder.class, sqlWhere,
				new Object[] { searchVal, searchVal, searchVal });
		if (qrElder.getTotalRecord() == 0) {
			throwExp("查询不到相关老者");
		}

		List<YrElderCostInventoryForm> formList = new ArrayList<YrElderCostInventoryForm>();

		for (YrElder elder : qrElder.getResultList()) {
			sqlWhere = "elder_id=?1 AND be_status<>2";

			QueryResult<YrElderBeHospital> qrElderBeHospital = elderBeHospitalService.find(YrElderBeHospital.class,
					sqlWhere, new Object[] { elder.getElderId() });
			YrElderBeHospitalForm beHospitalForm = null;
			if (qrElderBeHospital.getResultList().isEmpty()) {
				throwExp("查询不到该老者入院登记信息");
			}
			YrElderBeHospital elderBeHospital = qrElderBeHospital.getResultList().get(0);
			beHospitalForm = ObjectUtils.objectToObject(elderBeHospital, YrElderBeHospitalForm.class);
			beHospitalForm.setElderForm(ObjectUtils.objectToObject(elder, YrElderForm.class));

			YrBed bed = bedService.findOne(elderBeHospital.getBedId());
			if (null != bed) {
				beHospitalForm.setBedNumber(bed.getBedNumber());
			}

			sqlWhere = "subject_room_id=?1 AND manager_of_subject_room=1 AND status=0";

			QueryResult<YrStaffInfo> qrStaffInfo = staffInfoService.find(YrStaffInfo.class, sqlWhere,
					new Object[] { elderBeHospital.getSubjectRoomId() });
			if (qrStaffInfo.getTotalRecord() > 0) {
				beHospitalForm.setSubjectRoomManager(qrStaffInfo.getResultList().get(0).getName());
			}

			List<YrElderPayRecordForm> elderPayRecordForms = null;
			if (null == month) {
				sqlWhere = "elder_id=?1";
				elderPayRecordForms = getElderPayRecordForms(sqlWhere, new Object[] { elder.getElderId() });
			} else {
				// sqlWhere = "elder_id=?1 AND ((DATE_FORMAT(pay_date,'%Y-%m') =
				// ?2 AND cost_type<>12) OR (cost_type=12 AND "
				// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage
				// t WHERE t.elderArrearageId = o.relationId),'%Y-%m')=?2)) ";
				sqlWhere = "elder_id=?1 AND DATE_FORMAT(pay_date,'%Y-%m')=?2";
				elderPayRecordForms = getElderPayRecordForms(sqlWhere, new Object[] { elder.getElderId(), month });
			}

			List<YrElderArrearageForm> elderArrearageForms = null;
			if (null == month) {
				sqlWhere = "elder_id=?1 AND status=0";
				elderArrearageForms = getElderArrearageForms(sqlWhere, new Object[] { elder.getElderId() });
			} else {
				sqlWhere = "elder_id=?1 AND DATE_FORMAT(should_pay_date,'%Y-%m') = ?2 AND status=0";
				elderArrearageForms = getElderArrearageForms(sqlWhere, new Object[] { elder.getElderId(), month });
			}

			YrElderCostInventoryForm form = new YrElderCostInventoryForm();
			sqlWhere = "be_hospital_id=?1";
			YrOutFeeRecord outFeeRecord = null;
			QueryResult<YrOutFeeRecord> qrOutFeeRecord = outFeeRecordService.find(YrOutFeeRecord.class, sqlWhere,
					new Object[] { elderBeHospital.getBeHospitalId() });
			if (!qrOutFeeRecord.getResultList().isEmpty()) {
				outFeeRecord = qrOutFeeRecord.getResultList().get(0);
				YrOutFeeRecordForm outFeeRecordForm = ObjectUtils.objectToObject(outFeeRecord,
						YrOutFeeRecordForm.class);
				form.setOutFeeRecordForm(outFeeRecordForm);
			}

			sqlWhere = "elder_id=?1";
			QueryResult<YrElderWallet> qrElderWallet = elderWalletService.find(YrElderWallet.class, sqlWhere,
					new Object[] { elder.getElderId() });
			if (!qrElderWallet.getResultList().isEmpty()) {
				YrElderWalletForm elderWalletForm = ObjectUtils.objectToObject(qrElderWallet.getResultList().get(0),
						YrElderWalletForm.class);
				form.setElderWalletForm(elderWalletForm);
			}

			sqlWhere = "card_person_id=?1";
			QueryResult<YrMealCard> qrMealCard = mealCardService.find(YrMealCard.class, sqlWhere,
					new Object[] { elder.getElderId() });

			if (!qrMealCard.getResultList().isEmpty()) {
				YrMealCard mealCard = qrMealCard.getResultList().get(0);
				YrMealCardForm mealCardForm = ObjectUtils.objectToObject(mealCard, YrMealCardForm.class);
				form.setMealCardForm(mealCardForm);
			}
			// 查询出所有的预交款
			sqlWhere = "elder_id=?1 AND create_time>=?2";
			QueryResult<YrElderWalletRechargeRecord> reQueryResult = elderWalletRechargeRecordService.find(
					YrElderWalletRechargeRecord.class, sqlWhere,
					new Object[] { elder.getElderId(), beHospitalForm.getCreateTime() });

			Float prePay = 0F;
			for (YrElderWalletRechargeRecord rechargeRecord : reQueryResult.getResultList()) {
				prePay += rechargeRecord.getRechargeMoney();
			}

			Float totalFee = 0F;

			sqlWhere = "elder_id=?1 AND pay_way<>3";
			// 查询出所有的费用
			QueryResult<YrElderPayRecord> qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class,
					sqlWhere, new Object[] { elder.getElderId() });
			for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
				totalFee += elderPayRecord.getPayMoney();
			}

			sqlWhere = "elder_id=?1 AND source=1";
			// 查询出返回钱包的钱
			QueryResult<YrWalletReturn> qrWallerReturn = walletReturnService.find(YrWalletReturn.class, sqlWhere,
					new Object[] { elder.getElderId() });
			Float returnMoney = 0F;

			for (YrWalletReturn walletReturn : qrWallerReturn.getResultList()) {
				returnMoney += walletReturn.getReturnMoney();
			}
			sqlWhere = "elder_id=?1 AND status=0";
			QueryResult<YrBeHospitalPledge> qrBeHospitalPledge = beHospitalPledgeService.find(YrBeHospitalPledge.class,
					sqlWhere, new Object[] { elder.getElderId() });
			Float pledge = 0F;
			for (YrBeHospitalPledge beHospitalPledge : qrBeHospitalPledge.getResultList()) {
				pledge += beHospitalPledge.getPledge();
			}
			form.setPledge(pledge);
			form.setElderBeHospitalForm(beHospitalForm);
			form.setElderArrearageForms(elderArrearageForms);
			form.setElderPayRecordForms(elderPayRecordForms);
			form.setPrePay(prePay);
			form.setTotalFee(totalFee);
			form.setReturnMoney(returnMoney);

			formList.add(form);
		}
		result.setData(formList);
		return result;
	}

	@RequestMapping("findByBeHospitalId")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findByBeHospitalId(String beHospitalId) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (beHospitalId == null) {
			throwExp("参数有误");
		}
		YrElderBeHospital elderBeHospital = elderBeHospitalService.findOne(beHospitalId);
		if (null == elderBeHospital) {
			throwExp("查询不到相关住院登记信息");
		}

		// Date stateTime = null;
		// Date endTime = null;
		// if (elderBeHospital.getBeStatus() == 2) {// 如果已经出院
		// stateTime = elderBeHospital.getBeDate();
		// endTime = elderBeHospital.getOutDate();
		// } else {
		// stateTime = elderBeHospital.getBeDate();
		// }

		YrElderBeHospitalForm beHospitalForm = ObjectUtils.objectToObject(elderBeHospital, YrElderBeHospitalForm.class);

		YrElder elder = elderService.findOne(elderBeHospital.getElderId());

		if (null == elder) {
			throwExp("查询不到相关老者信息");
		}
		beHospitalForm.setElderForm(ObjectUtils.objectToObject(elder, YrElderForm.class));

		YrBed bed = bedService.findOne(elderBeHospital.getBedId());
		if (null != bed) {
			beHospitalForm.setBedNumber(bed.getBedNumber());
		}

		String sqlWhere = "subject_room_id=?1 AND manager_of_subject_room=1 AND status=0";

		QueryResult<YrStaffInfo> qrStaffInfo = staffInfoService.find(YrStaffInfo.class, sqlWhere,
				new Object[] { elderBeHospital.getSubjectRoomId() });
		if (qrStaffInfo.getTotalRecord() > 0) {
			beHospitalForm.setSubjectRoomManager(qrStaffInfo.getResultList().get(0).getName());
		}

		List<YrElderPayRecordForm> elderPayRecordForms = null;

		// if(endTime == null){//如果正在住院
		// sqlWhere = "elder_id=?1 AND ((be_hospital_id=?2 AND cost_type<>12) OR
		// (cost_type=12 AND "
		// + "(SELECT t.beHospitalId FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId)=?2))";
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2";
		elderPayRecordForms = getElderPayRecordForms(sqlWhere, new Object[] { elder.getElderId(), beHospitalId });
		// }else {
		// sqlWhere = "elder_id=?1 AND ((create_time >=?2 AND create_time<=?3
		// AND cost_type<>12) OR (cost_type=12 AND "
		// + "(SELECT t.createTime FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId)>=?2)"
		// + " (SELECT t.createTime FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId)<=?3)) ";
		// elderPayRecordForms = getElderPayRecordForms(sqlWhere,
		// new Object[] { elder.getElderId(),
		// elderBeHospital.getCreateTime(),stateTime,endTime});
		// }

		List<YrElderArrearageForm> elderArrearageForms = null;

		// if (endTime == null){//如果正在住院
		sqlWhere = "elder_id=?1 AND status=0 AND be_hospital_id=?2";
		elderArrearageForms = getElderArrearageForms(sqlWhere, new Object[] { elder.getElderId(), beHospitalId });
		// } else {
		// sqlWhere = "elder_id=?1 AND DATE_FORMAT(create_time,'%Y-%m') >=?2 AND
		// DATE_FORMAT(create_time,'%Y-%m') <=?3 "
		// + " AND status=0";
		// elderArrearageForms = getElderArrearageForms(sqlWhere, new Object[] {
		// elder.getElderId(), stateTime,endTime});
		// }

		YrElderCostInventoryForm form = new YrElderCostInventoryForm();
		sqlWhere = "be_hospital_id=?1";
		YrOutFeeRecord outFeeRecord = null;
		QueryResult<YrOutFeeRecord> qrOutFeeRecord = outFeeRecordService.find(YrOutFeeRecord.class, sqlWhere,
				new Object[] { elderBeHospital.getBeHospitalId() });
		if (!qrOutFeeRecord.getResultList().isEmpty()) {
			outFeeRecord = qrOutFeeRecord.getResultList().get(0);
			YrOutFeeRecordForm outFeeRecordForm = ObjectUtils.objectToObject(outFeeRecord, YrOutFeeRecordForm.class);
			form.setOutFeeRecordForm(outFeeRecordForm);
		}

		sqlWhere = "elder_id=?1";
		QueryResult<YrElderWallet> qrElderWallet = elderWalletService.find(YrElderWallet.class, sqlWhere,
				new Object[] { elder.getElderId() });
		if (!qrElderWallet.getResultList().isEmpty()) {
			YrElderWalletForm elderWalletForm = ObjectUtils.objectToObject(qrElderWallet.getResultList().get(0),
					YrElderWalletForm.class);
			form.setElderWalletForm(elderWalletForm);
		}

		sqlWhere = "card_person_id=?1";
		QueryResult<YrMealCard> qrMealCard = mealCardService.find(YrMealCard.class, sqlWhere,
				new Object[] { elder.getElderId() });

		if (!qrMealCard.getResultList().isEmpty()) {
			YrMealCard mealCard = qrMealCard.getResultList().get(0);
			YrMealCardForm mealCardForm = ObjectUtils.objectToObject(mealCard, YrMealCardForm.class);
			form.setMealCardForm(mealCardForm);
		}

		// 查询出所有的预交款
		QueryResult<YrElderWalletRechargeRecord> reQueryResult = null;
		// if (endTime == null){//如果正在住院
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2";
		reQueryResult = elderWalletRechargeRecordService.find(YrElderWalletRechargeRecord.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		// }else {
		// sqlWhere = "elder_id=?1 AND create_time>=?2 AND create_time<=?3";
		// reQueryResult = elderWalletRechargeRecordService.find(
		// YrElderWalletRechargeRecord.class, sqlWhere,new Object[] {
		// elder.getElderId(),stateTime,endTime});
		// }
		Float prePay = 0F;
		for (YrElderWalletRechargeRecord rechargeRecord : reQueryResult.getResultList()) {
			prePay += rechargeRecord.getRechargeMoney();
		}

		QueryResult<YrElderPayRecord> qrElderPayRecord = null;
		// if (endTime == null){//如果正在住院
		// 查询出所有的费用
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2 AND pay_way<>3";
		qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		// }else {
		// sqlWhere = "elder_id=?1 AND create_time>=?2 AND create_time<=?3 AND
		// pay_way<>3";
		// qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class,
		// sqlWhere,
		// new Object[] { elder.getElderId(), stateTime ,endTime});
		// }

		Float totalFee = 0F;
		for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
			totalFee += elderPayRecord.getPayMoney();
		}
		QueryResult<YrWalletReturn> qrWallerReturn = null;
		// if (endTime == null){//如果正在住院
		// 查询出返回钱包的钱
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2 AND source=1";
		qrWallerReturn = walletReturnService.find(YrWalletReturn.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		// }else {
		// sqlWhere = "elder_id=?1 AND create_time>=?2 AND create_time<=?3";
		// qrWallerReturn = walletReturnService.find(YrWalletReturn.class,
		// sqlWhere,
		// new Object[] { elder.getElderId(), stateTime,endTime});
		// }
		Float returnMoney = 0F;

		for (YrWalletReturn walletReturn : qrWallerReturn.getResultList()) {
			returnMoney += walletReturn.getReturnMoney();
		}
		sqlWhere = "status=0 AND be_hospital_id=?1";
		QueryResult<YrBeHospitalPledge> qrBeHospitalPledge = null;
		// if (endTime == null){//如果正在住院
		// 查询出返回钱包的钱
		sqlWhere = "be_hospital_id=?1";
		qrBeHospitalPledge = beHospitalPledgeService.find(YrBeHospitalPledge.class, sqlWhere,
				new Object[] { beHospitalId });
		// }else {
		// sqlWhere = "elder_id=?1 AND create_time>=?2 AND create_time<=?3";
		// qrBeHospitalPledge =
		// beHospitalPledgeService.find(YrBeHospitalPledge.class, sqlWhere,
		// new Object[] { elder.getElderId(), stateTime,endTime});
		// }
		Float pledge = 0F;
		for (YrBeHospitalPledge beHospitalPledge : qrBeHospitalPledge.getResultList()) {
			pledge += beHospitalPledge.getPledge();
		}
		form.setPledge(pledge);
		form.setElderBeHospitalForm(beHospitalForm);
		form.setElderArrearageForms(elderArrearageForms);
		form.setElderPayRecordForms(elderPayRecordForms);
		form.setPrePay(prePay);
		form.setTotalFee(totalFee);
		form.setReturnMoney(returnMoney);

		List<YrElderCostInventoryForm> formList = new ArrayList<YrElderCostInventoryForm>();
		formList.add(form);

		result.setData(formList);
		return result;
	}

	@RequestMapping("findCostInventory")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findCostInventory(String searchVal, String dateSince, String dateEnd)
			throws MyException, InstantiationException, IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (searchVal == null || dateSince == null || dateEnd == null) {
			throwExp("参数有误");
		}
		String sqlWhere = "name=?1 OR card_id=?2";

		QueryResult<YrElder> qrElder = elderService.find(YrElder.class, sqlWhere,
				new Object[] { searchVal, searchVal });
		if (qrElder.getTotalRecord() == 0) {
			throwExp("查询不到相关老者");
		}

		List<YrElderCostInventoryForm> formList = new ArrayList<YrElderCostInventoryForm>();
		for (YrElder elder : qrElder.getResultList()) {
			sqlWhere = "elder_id=?1 AND be_status<>2";

			QueryResult<YrElderBeHospital> qrElderBeHospital = elderBeHospitalService.find(YrElderBeHospital.class,
					sqlWhere, new Object[] { elder.getElderId() });
			if (qrElderBeHospital.getResultList().isEmpty()) {
				throwExp("查询不到老者相关住院登记信息");
			}

			YrElderBeHospital elderBeHospital = qrElderBeHospital.getResultList().get(0);
			YrElderBeHospitalForm beHospitalForm = ObjectUtils.objectToObject(elderBeHospital,
					YrElderBeHospitalForm.class);
			beHospitalForm.setElderForm(ObjectUtils.objectToObject(elder, YrElderForm.class));

			YrBed bed = bedService.findOne(elderBeHospital.getBedId());
			if (null != bed) {
				beHospitalForm.setBedNumber(bed.getBedNumber());
			}

			sqlWhere = "subject_room_id=?1 AND manager_of_subject_room=1 AND status=0";

			QueryResult<YrStaffInfo> qrStaffInfo = staffInfoService.find(YrStaffInfo.class, sqlWhere,
					new Object[] { elderBeHospital.getSubjectRoomId() });
			if (qrStaffInfo.getTotalRecord() > 0) {
				beHospitalForm.setSubjectRoomManager(qrStaffInfo.getResultList().get(0).getName());
			}

			List<YrElderPayRecordForm> elderPayRecordForms = null;

			if (dateSince == null && dateEnd == null) {
				sqlWhere = "elder_id=?1";
				elderPayRecordForms = getElderPayRecordForms(sqlWhere, new Object[] { elder.getElderId() });
			} else {
				// sqlWhere = "elder_id=?1 AND
				// ((DATE_FORMAT(pay_date,'%Y-%m-%d') >= ?2 AND
				// DATE_FORMAT(pay_date,'%Y-%m-%d')<=?3 AND cost_type<>12) OR
				// (cost_type=12 AND "
				// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage
				// t WHERE t.elderArrearageId = o.relationId),'%Y-%m-%d')>=?2
				// AND "
				// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage
				// t WHERE t.elderArrearageId = o.relationId),'%Y-%m-%d')<=?3))
				// ";
				sqlWhere = "elder_id=?1 AND DATE_FORMAT(pay_date,'%Y-%m-%d')>=?2 AND DATE_FORMAT(pay_date,'%Y-%m-%d')<=?3";
				elderPayRecordForms = getElderPayRecordForms(sqlWhere,
						new Object[] { elder.getElderId(), dateSince, dateEnd });
			}

			List<YrElderArrearageForm> elderArrearageForms = null;

			if (dateSince == null && dateEnd == null) {
				sqlWhere = "elder_id=?1 AND status=0";
				elderArrearageForms = getElderArrearageForms(sqlWhere, new Object[] { elder.getElderId() });
			} else {
				sqlWhere = "elder_id=?1 AND DATE_FORMAT(should_pay_date,'%Y-%m-%d') >= ?2 AND DATE_FORMAT(should_pay_date,'%Y-%m-%d')<=?3 AND status=0";
				elderArrearageForms = getElderArrearageForms(sqlWhere,
						new Object[] { elder.getElderId(), dateSince, dateEnd });
			}

			YrElderCostInventoryForm form = new YrElderCostInventoryForm();
			sqlWhere = "be_hospital_id=?1";
			YrOutFeeRecord outFeeRecord = null;
			QueryResult<YrOutFeeRecord> qrOutFeeRecord = outFeeRecordService.find(YrOutFeeRecord.class, sqlWhere,
					new Object[] { elderBeHospital.getBeHospitalId() });
			if (!qrOutFeeRecord.getResultList().isEmpty()) {
				outFeeRecord = qrOutFeeRecord.getResultList().get(0);
				YrOutFeeRecordForm outFeeRecordForm = ObjectUtils.objectToObject(outFeeRecord,
						YrOutFeeRecordForm.class);
				form.setOutFeeRecordForm(outFeeRecordForm);
			}

			sqlWhere = "elder_id=?1";
			QueryResult<YrElderWallet> qrElderWallet = elderWalletService.find(YrElderWallet.class, sqlWhere,
					new Object[] { elder.getElderId() });
			if (!qrElderWallet.getResultList().isEmpty()) {
				YrElderWalletForm elderWalletForm = ObjectUtils.objectToObject(qrElderWallet.getResultList().get(0),
						YrElderWalletForm.class);
				form.setElderWalletForm(elderWalletForm);
			}

			sqlWhere = "card_person_id=?1";
			QueryResult<YrMealCard> qrMealCard = mealCardService.find(YrMealCard.class, sqlWhere,
					new Object[] { elder.getElderId() });

			if (!qrMealCard.getResultList().isEmpty()) {
				YrMealCard mealCard = qrMealCard.getResultList().get(0);
				YrMealCardForm mealCardForm = ObjectUtils.objectToObject(mealCard, YrMealCardForm.class);
				form.setMealCardForm(mealCardForm);
			}
			// 查询出所有的预交款
			sqlWhere = "elder_id=?1";
			QueryResult<YrElderWalletRechargeRecord> reQueryResult = elderWalletRechargeRecordService
					.find(YrElderWalletRechargeRecord.class, sqlWhere, new Object[] { elder.getElderId() });

			Float prePay = 0F;
			for (YrElderWalletRechargeRecord rechargeRecord : reQueryResult.getResultList()) {
				prePay += rechargeRecord.getRechargeMoney();
			}
			sqlWhere = "elder_id=?1 AND pay_way<>3";
			Float totalFee = 0F;
			// 查询出所有的费用
			QueryResult<YrElderPayRecord> qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class,
					sqlWhere, new Object[] { elder.getElderId() });
			for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
				totalFee += elderPayRecord.getPayMoney();
			}
			sqlWhere = "elder_id=?1 AND source=1";
			// 查询出返回钱包的钱
			QueryResult<YrWalletReturn> qrWallerReturn = walletReturnService.find(YrWalletReturn.class, sqlWhere,
					new Object[] { elder.getElderId() });
			Float returnMoney = 0F;

			for (YrWalletReturn walletReturn : qrWallerReturn.getResultList()) {
				returnMoney += walletReturn.getReturnMoney();
			}
			sqlWhere = "elder_id=?1 AND status=0";
			QueryResult<YrBeHospitalPledge> qrBeHospitalPledge = beHospitalPledgeService.find(YrBeHospitalPledge.class,
					sqlWhere, new Object[] { elder.getElderId() });
			Float pledge = 0F;
			for (YrBeHospitalPledge beHospitalPledge : qrBeHospitalPledge.getResultList()) {
				pledge += beHospitalPledge.getPledge();
			}
			form.setPledge(pledge);
			form.setElderBeHospitalForm(beHospitalForm);
			form.setElderArrearageForms(elderArrearageForms);
			form.setElderPayRecordForms(elderPayRecordForms);
			form.setPrePay(prePay);
			form.setTotalFee(totalFee);
			form.setReturnMoney(returnMoney);

			formList.add(form);
		}
		result.setData(formList);
		return result;
	}

	@RequestMapping("findCostInventoryBybeHospitalId")
	@ResponseBody
	public HTTPResult<YrElderCostInventoryForm> findCostInventoryBybeHospitalId(String beHospitalId, String dateSince,
			String dateEnd) throws MyException, InstantiationException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		HTTPResult<YrElderCostInventoryForm> result = new HTTPResult<YrElderCostInventoryForm>();
		if (beHospitalId == null || dateSince == null || dateEnd == null) {
			throwExp("参数有误");
		}
		List<YrElderCostInventoryForm> formList = new ArrayList<YrElderCostInventoryForm>();

		YrElderBeHospital elderBeHospital = elderBeHospitalService.findOne(beHospitalId);
		YrElderBeHospitalForm beHospitalForm = ObjectUtils.objectToObject(elderBeHospital, YrElderBeHospitalForm.class);

		YrElder elder = elderService.findOne(elderBeHospital.getElderId());
		if (null == elder) {
			throwExp("查询不到老者信息");
		}
		beHospitalForm.setElderForm(ObjectUtils.objectToObject(elder, YrElderForm.class));

		YrBed bed = bedService.findOne(elderBeHospital.getBedId());
		if (null != bed) {
			beHospitalForm.setBedNumber(bed.getBedNumber());
		}

		String sqlWhere = "subject_room_id=?1 AND manager_of_subject_room=1 AND status=0";

		QueryResult<YrStaffInfo> qrStaffInfo = staffInfoService.find(YrStaffInfo.class, sqlWhere,
				new Object[] { elderBeHospital.getSubjectRoomId() });
		if (qrStaffInfo.getTotalRecord() > 0) {
			beHospitalForm.setSubjectRoomManager(qrStaffInfo.getResultList().get(0).getName());
		}

		List<YrElderPayRecordForm> elderPayRecordForms = null;

		// sqlWhere = "elder_id=?1 AND ((DATE_FORMAT(pay_date,'%Y-%m-%d') >= ?2
		// AND DATE_FORMAT(pay_date,'%Y-%m-%d')<=?3 AND cost_type<>12 AND
		// be_hospital_id=?4) OR (cost_type=12 AND "
		// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId),'%Y-%m-%d')>=?2 AND "
		// + "DATE_FORMAT((SELECT t.shouldPayDate FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId),'%Y-%m-%d')<=?3 AND "
		// + "(SELECT t.beHospitalId FROM YrElderArrearage t WHERE
		// t.elderArrearageId = o.relationId)=?4)) ";
		sqlWhere = "elder_id=?1 AND DATE_FORMAT(pay_date,'%Y-%m-%d')>=?2 AND DATE_FORMAT(pay_date,'%Y-%m-%d')<=?3 AND be_hospital_id=?4";
		elderPayRecordForms = getElderPayRecordForms(sqlWhere,
				new Object[] { elder.getElderId(), dateSince, dateEnd, beHospitalId });

		List<YrElderArrearageForm> elderArrearageForms = null;

		sqlWhere = "elder_id=?1 AND DATE_FORMAT(should_pay_date,'%Y-%m-%d') >= ?2 "
				+ "AND DATE_FORMAT(should_pay_date,'%Y-%m-%d')<=?3 AND status=0 AND be_hospital_id=?4";
		elderArrearageForms = getElderArrearageForms(sqlWhere,
				new Object[] { elder.getElderId(), dateSince, dateEnd, beHospitalId });

		YrElderCostInventoryForm form = new YrElderCostInventoryForm();
		sqlWhere = "be_hospital_id=?1";
		YrOutFeeRecord outFeeRecord = null;
		QueryResult<YrOutFeeRecord> qrOutFeeRecord = outFeeRecordService.find(YrOutFeeRecord.class, sqlWhere,
				new Object[] { elderBeHospital.getBeHospitalId() });
		if (!qrOutFeeRecord.getResultList().isEmpty()) {
			outFeeRecord = qrOutFeeRecord.getResultList().get(0);
			YrOutFeeRecordForm outFeeRecordForm = ObjectUtils.objectToObject(outFeeRecord, YrOutFeeRecordForm.class);
			form.setOutFeeRecordForm(outFeeRecordForm);
		}

		sqlWhere = "elder_id=?1";
		QueryResult<YrElderWallet> qrElderWallet = elderWalletService.find(YrElderWallet.class, sqlWhere,
				new Object[] { elder.getElderId() });
		if (!qrElderWallet.getResultList().isEmpty()) {
			YrElderWalletForm elderWalletForm = ObjectUtils.objectToObject(qrElderWallet.getResultList().get(0),
					YrElderWalletForm.class);
			form.setElderWalletForm(elderWalletForm);
		}

		sqlWhere = "card_person_id=?1";
		QueryResult<YrMealCard> qrMealCard = mealCardService.find(YrMealCard.class, sqlWhere,
				new Object[] { elder.getElderId() });

		if (!qrMealCard.getResultList().isEmpty()) {
			YrMealCard mealCard = qrMealCard.getResultList().get(0);
			YrMealCardForm mealCardForm = ObjectUtils.objectToObject(mealCard, YrMealCardForm.class);
			form.setMealCardForm(mealCardForm);
		}

		// 查询出所有的预交款
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2";
		QueryResult<YrElderWalletRechargeRecord> reQueryResult = elderWalletRechargeRecordService
				.find(YrElderWalletRechargeRecord.class, sqlWhere, new Object[] { elder.getElderId(), beHospitalId });

		Float prePay = 0F;
		for (YrElderWalletRechargeRecord rechargeRecord : reQueryResult.getResultList()) {
			prePay += rechargeRecord.getRechargeMoney();
		}
		sqlWhere = "elder_id=?1 AND pay_way<>3 AND be_hospital_id=?2";
		Float totalFee = 0F;
		// 查询出所有的费用
		QueryResult<YrElderPayRecord> qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
			totalFee += elderPayRecord.getPayMoney();
		}
		sqlWhere = "elder_id=?1 AND be_hospital_id=?2 AND source=1";
		// 查询出返回钱包的钱
		QueryResult<YrWalletReturn> qrWallerReturn = walletReturnService.find(YrWalletReturn.class, sqlWhere,
				new Object[] { elder.getElderId(), beHospitalId });
		Float returnMoney = 0F;

		for (YrWalletReturn walletReturn : qrWallerReturn.getResultList()) {
			returnMoney += walletReturn.getReturnMoney();
		}
		sqlWhere = "status=0 AND be_hospital_id=?1";
		QueryResult<YrBeHospitalPledge> qrBeHospitalPledge = beHospitalPledgeService.find(YrBeHospitalPledge.class,
				sqlWhere, new Object[] { beHospitalId });
		Float pledge = 0F;
		for (YrBeHospitalPledge beHospitalPledge : qrBeHospitalPledge.getResultList()) {
			pledge += beHospitalPledge.getPledge();
		}
		form.setPledge(pledge);
		form.setElderBeHospitalForm(beHospitalForm);
		form.setElderArrearageForms(elderArrearageForms);
		form.setElderPayRecordForms(elderPayRecordForms);
		form.setPrePay(prePay);
		form.setTotalFee(totalFee);
		form.setReturnMoney(returnMoney);

		formList.add(form);
		result.setData(formList);
		return result;
	}

	public List<YrElderArrearageForm> getElderArrearageForms(String sqlWhere, Object[] objects) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("shouldPayDate", "DESC");
		map.put("createTime", "DESC");

		QueryResult<YrElderArrearage> qrElderArrearage = elderArrearageService.find(YrElderArrearage.class, sqlWhere,
				objects, map);
		List<YrElderArrearageForm> elderArrearageForms = new ArrayList<YrElderArrearageForm>();
		for (YrElderArrearage elderArrearage : qrElderArrearage.getResultList()) {
			YrElderArrearageForm elderPayRecordForm = ObjectUtils.objectToObject(elderArrearage,
					YrElderArrearageForm.class);
			if (elderArrearage.getCreateId() == null || elderArrearage.getCreateId().equals("-1")) {
				elderPayRecordForm.setHandler("系统");
			} else {
				YrStaffInfo staffInfo = staffInfoService.findOne(elderArrearage.getCreateId());
				elderPayRecordForm.setHandler(staffInfo == null ? "未知" : staffInfo.getName());
			}
			elderArrearageForms.add(elderPayRecordForm);
		}
		return elderArrearageForms;
	}

	public List<YrElderPayRecordForm> getElderPayRecordForms(String sqlWhere, Object[] objects) throws MyException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("payDate", "DESC");
		map.put("createTime", "DESC");

		QueryResult<YrElderPayRecord> qrElderPayRecord = elderPayRecordService.find(YrElderPayRecord.class, sqlWhere,
				objects, map);
		List<YrElderPayRecordForm> elderPayRecordForms = new ArrayList<YrElderPayRecordForm>();
		for (YrElderPayRecord elderPayRecord : qrElderPayRecord.getResultList()) {
			YrElderPayRecordForm elderPayRecordForm = ObjectUtils.objectToObject(elderPayRecord,
					YrElderPayRecordForm.class);
			if (elderPayRecord.getCreateId() == null || elderPayRecord.getCreateId().equals("-1")) {
				elderPayRecordForm.setHandler("系统");
			} else {
				YrStaffInfo staffInfo = staffInfoService.findOne(elderPayRecord.getCreateId());
				elderPayRecordForm.setHandler(staffInfo == null ? "未知" : staffInfo.getName());
			}
			elderPayRecordForms.add(elderPayRecordForm);
		}
		return elderPayRecordForms;
	}

	@RequestMapping("findSummary")
	@ResponseBody
	public HTTPResult<SubjectRoomSummaryItem> findSummary(String dateSince, String dateEnd) throws MyException {
		HTTPResult<SubjectRoomSummaryItem> result = new HTTPResult<SubjectRoomSummaryItem>();

		String sqlWhere = "DATE_FORMAT(pay_date,'%Y-%m-%d')>=?1 AND DATE_FORMAT(pay_date,'%Y-%m-%d')<=?2";

		QueryResult<YrElderPayRecord> qrElderPayRecord = selfService.find(YrElderPayRecord.class, sqlWhere,
				new Object[] { dateSince, dateEnd });

		result.setData(getSubjectRoomSummaryItemList(qrElderPayRecord.getResultList()));
		return result;
	}

	/**
	 * 按科室获取非vip卡费用的总费用
	 * 
	 * @param dateSince
	 * @param dateEnd
	 * @return
	 * @throws MyException
	 */
	@RequestMapping("findSubjectRoomSummaryList")
	@ResponseBody
	private HTTPResult<SubjectRoomSummaryList> findSubjectRoomSummaryList(String dateSince, String dateEnd)
			throws MyException {
		HTTPResult<SubjectRoomSummaryList> result = new HTTPResult<SubjectRoomSummaryList>();

		// String sqlWhere = "DATE_FORMAT(pay_date,'%Y-%m-%d')>=?1 AND
		// DATE_FORMAT(pay_date,'%Y-%m-%d')<=?2 AND pay_way<>3";
		//
		// QueryResult<YrElderPayRecord> qrElderPayRecord =
		// selfService.find(YrElderPayRecord.class, sqlWhere,
		// new Object[] { dateSince, dateEnd });

		String sql = "SELECT a FROM YrElderPayRecord a,YrElderBeHospital b WHERE b.beHospitalId = a.beHospitalId AND "
				+ "a.payWay<>3 AND DATE_FORMAT(a.payDate,'%Y-%m-%d')>=?1 AND DATE_FORMAT(a.payDate,'%Y-%m-%d')<=?2 "
				+ "ORDER BY b.subjectRoomName asc";

		List<YrElderPayRecord> elderPayRecords = elderPayRecordService.findByJPQL(sql,
				new Object[] { dateSince, dateEnd });

		List<SubjectRoomSummaryItem> subjectRoomSummaryItems = getSubjectRoomSummaryItemList(elderPayRecords);
		Map<String, List<SubjectRoomSummaryItem>> map = new HashMap<String, List<SubjectRoomSummaryItem>>();

		for (SubjectRoomSummaryItem subjectRoomSummaryItem : subjectRoomSummaryItems) {
			List<SubjectRoomSummaryItem> _subjectRoomSummaryItems = null;
			if (map.containsKey(subjectRoomSummaryItem.getSubjectRoomName())) {
				_subjectRoomSummaryItems = map.get(subjectRoomSummaryItem.getSubjectRoomName());
			} else {
				_subjectRoomSummaryItems = new ArrayList<SubjectRoomSummaryItem>();
			}
			_subjectRoomSummaryItems.add(subjectRoomSummaryItem);
			map.put(subjectRoomSummaryItem.getSubjectRoomName(), _subjectRoomSummaryItems);
		}

		List<SubjectRoomSummaryList> subjectRoomSummaryLists = new ArrayList<SubjectRoomSummaryList>();

		// 这里将map.entrySet()转换成list
		List<Map.Entry<String, List<SubjectRoomSummaryItem>>> list = new ArrayList<Map.Entry<String, List<SubjectRoomSummaryItem>>>(
				map.entrySet());
		// 然后通过比较器来实现排序
		Collections.sort(list, new Comparator<Map.Entry<String, List<SubjectRoomSummaryItem>>>() {

			@Override
			public int compare(Entry<String, List<SubjectRoomSummaryItem>> o1,
					Entry<String, List<SubjectRoomSummaryItem>> o2) {
				return o1.getValue().get(0).getSubjectRoomName().compareTo(o2.getValue().get(0).getSubjectRoomName());
			}

		});

		for (Map.Entry<String, List<SubjectRoomSummaryItem>> entry : list) {
			SubjectRoomSummaryList subjectRoomSummaryList = new SubjectRoomSummaryList();
			subjectRoomSummaryList.setSubjectRoomSummaryItems(entry.getValue());
			subjectRoomSummaryLists.add(subjectRoomSummaryList);
		}

		result.setData(subjectRoomSummaryLists);
		return result;
	}

	@RequestMapping("findElderVipSummaryList")
	@ResponseBody
	public HTTPResult<YrElderVipSummary> findElderVipSummaryList(String dateSince, String dateEnd) throws MyException {
		HTTPResult<YrElderVipSummary> result = new HTTPResult<YrElderVipSummary>();

		String sql = "SELECT a FROM YrElderPayRecord a,YrElderBeHospital b WHERE b.beHospitalId = a.beHospitalId AND "
				+ "DATE_FORMAT(a.payDate,'%Y-%m-%d')>=?1 AND DATE_FORMAT(a.payDate,'%Y-%m-%d')<=?2 AND a.payWay=3 "
				+ "ORDER BY b.subjectRoomName asc";

		List<YrElderPayRecord> elderPayRecords = elderPayRecordService.findByJPQL(sql,
				new Object[] { dateSince, dateEnd });

		List<YrElderVipSummaryItem> elderVipSummaryItems = getElderVipSummaryList(elderPayRecords);
		Map<String, List<YrElderVipSummaryItem>> map = new HashMap<String, List<YrElderVipSummaryItem>>();

		for (YrElderVipSummaryItem elderVipSummaryItem : elderVipSummaryItems) {
			List<YrElderVipSummaryItem> _elderVipSummaryItems = null;
			if (map.containsKey(elderVipSummaryItem.getSubjectRoomName())) {
				_elderVipSummaryItems = map.get(elderVipSummaryItem.getSubjectRoomName());
			} else {
				_elderVipSummaryItems = new ArrayList<YrElderVipSummaryItem>();
			}
			_elderVipSummaryItems.add(elderVipSummaryItem);
			map.put(elderVipSummaryItem.getSubjectRoomName(), _elderVipSummaryItems);
		}

		List<YrElderVipSummary> subjectRoomSummaryLists = new ArrayList<YrElderVipSummary>();

		// 这里将map.entrySet()转换成list
		List<Map.Entry<String, List<YrElderVipSummaryItem>>> list = new ArrayList<Map.Entry<String, List<YrElderVipSummaryItem>>>(
				map.entrySet());
		// 然后通过比较器来实现排序
		Collections.sort(list, new Comparator<Map.Entry<String, List<YrElderVipSummaryItem>>>() {

			@Override
			public int compare(Entry<String, List<YrElderVipSummaryItem>> o1,
					Entry<String, List<YrElderVipSummaryItem>> o2) {
				return o1.getValue().get(0).getSubjectRoomName().compareTo(o2.getValue().get(0).getSubjectRoomName());
			}

		});

		for (Map.Entry<String, List<YrElderVipSummaryItem>> entry : list) {
			YrElderVipSummary elderVipSummary = new YrElderVipSummary();
			elderVipSummary.setElderVipSummaryItems(entry.getValue());
			subjectRoomSummaryLists.add(elderVipSummary);
		}

		result.setData(subjectRoomSummaryLists);
		return result;
	}

	private List<SubjectRoomSummaryItem> getSubjectRoomSummaryItemList(List<YrElderPayRecord> elderPayRecords)
			throws MyException {
		Map<String, SubjectRoomSummaryItem> map = new HashMap<String, SubjectRoomSummaryItem>();

		for (YrElderPayRecord elderPayRecord : elderPayRecords) {
			SubjectRoomSummaryItem subjectRoomSummaryItem = null;
			if (map.containsKey(elderPayRecord.getBeHospitalId()+elderPayRecord.getSubjectRoomId())) {
				subjectRoomSummaryItem = map.get(elderPayRecord.getBeHospitalId()+elderPayRecord.getSubjectRoomId());
			} else {
				subjectRoomSummaryItem = new SubjectRoomSummaryItem();
				subjectRoomSummaryItem.setBeHospitalId(elderPayRecord.getBeHospitalId());
				subjectRoomSummaryItem.setElderName(elderPayRecord.getElderName());
				subjectRoomSummaryItem.setBaseServiceCost(0F);
				subjectRoomSummaryItem.setBedCost(0F);
				subjectRoomSummaryItem.setEleCost(0F);
				subjectRoomSummaryItem.setHandCost(0F);
				subjectRoomSummaryItem.setHotWaterCost(0F);
				subjectRoomSummaryItem.setIndiCost(0F);
				subjectRoomSummaryItem.setMaterialCost(0F);
				subjectRoomSummaryItem.setNursingCost(0F);
				subjectRoomSummaryItem.setWaterCost(0F);
				subjectRoomSummaryItem.setCostDesc(elderPayRecord.getCostDesc());
			}
			updayeSubjectRoomSummaryItem(elderPayRecord, subjectRoomSummaryItem);
			map.put(elderPayRecord.getBeHospitalId()+elderPayRecord.getSubjectRoomId(), subjectRoomSummaryItem);
		}
		LinkedList<SubjectRoomSummaryItem> subjectRoomSummaryItems = new LinkedList<SubjectRoomSummaryItem>();
		List<YrElderBeHospital> allElderBeHospital = elderBeHospitalService.findAll();
		Map<String, YrElderBeHospital> elderBeHospitalMap = new HashMap<String, YrElderBeHospital>();
		for (YrElderBeHospital entity : allElderBeHospital) {
			elderBeHospitalMap.put(entity.getBeHospitalId(), entity);
		}
		for (Map.Entry<String, SubjectRoomSummaryItem> entry : map.entrySet()) {
			SubjectRoomSummaryItem subjectRoomSummaryItem = entry.getValue();
			if (null != subjectRoomSummaryItem.getBeHospitalId()) {
				YrElderBeHospital elderBeHospital = elderBeHospitalMap.get(subjectRoomSummaryItem.getBeHospitalId());
				if (null != elderBeHospital) {
					subjectRoomSummaryItem.setBedNumber(elderBeHospital.getBedNumber());
					subjectRoomSummaryItem.setSubjectRoomName(elderBeHospital.getSubjectRoomName());
					subjectRoomSummaryItem.setBeNumber(elderBeHospital.getBeNumber());
					subjectRoomSummaryItem.setBeStatus(elderBeHospital.getBeStatus());
				}else {
					subjectRoomSummaryItem.setBedNumber("");
					subjectRoomSummaryItem.setSubjectRoomName("院外");
					subjectRoomSummaryItem.setBeNumber("");
				}
			}
			subjectRoomSummaryItems.add(subjectRoomSummaryItem);
		}

		Collections.sort(subjectRoomSummaryItems, new Comparator<SubjectRoomSummaryItem>() {

			@Override
			public int compare(SubjectRoomSummaryItem o1, SubjectRoomSummaryItem o2) {
				return o1.getBedNumber().compareTo(o2.getBedNumber());
			}
		});
		return subjectRoomSummaryItems;
	}

	private List<YrElderVipSummaryItem> getElderVipSummaryList(List<YrElderPayRecord> elderPayRecords)
			throws MyException {
		Map<String, YrElderVipSummaryItem> map = new HashMap<String, YrElderVipSummaryItem>();

		for (YrElderPayRecord elderPayRecord : elderPayRecords) {
			YrElderVipSummaryItem elderVipSummaryItem = null;
			if (map.containsKey(elderPayRecord.getBeHospitalId() + elderPayRecord.getRelationId())) {
				elderVipSummaryItem = map.get(elderPayRecord.getBeHospitalId() + elderPayRecord.getRelationId());
				elderVipSummaryItem.setVipBedCost(elderVipSummaryItem.getVipBedCost() + elderPayRecord.getPayMoney());
			} else {
				elderVipSummaryItem = new YrElderVipSummaryItem();
				elderVipSummaryItem.setBeHospitalId(elderPayRecord.getBeHospitalId());
				elderVipSummaryItem.setElderName(elderPayRecord.getElderName());
				elderVipSummaryItem.setVipBedCost(elderPayRecord.getPayMoney());
				elderVipSummaryItem.setUserVipCardId(elderPayRecord.getRelationId());
			}
			map.put(elderPayRecord.getBeHospitalId() + elderPayRecord.getRelationId(), elderVipSummaryItem);
		}

		List<YrElderBeHospital> allElderBeHospital = elderBeHospitalService.findAll();
		Map<String, YrElderBeHospital> elderBeHospitalMap = new HashMap<String, YrElderBeHospital>();
		for (YrElderBeHospital entity : allElderBeHospital) {
			elderBeHospitalMap.put(entity.getBeHospitalId(), entity);
		}

		List<YrUserVipCard> allUserVipCard = userVipCardService.findAll();
		Map<String, YrUserVipCard> userVipCardMap = new HashMap<String, YrUserVipCard>();
		for (YrUserVipCard entity : allUserVipCard) {
			userVipCardMap.put(entity.getUserVipCardId(), entity);
		}

		List<YrElderVipSummaryItem> elderVipSummaryItems = new ArrayList<YrElderVipSummaryItem>();
		for (Map.Entry<String, YrElderVipSummaryItem> entry : map.entrySet()) {
			YrElderVipSummaryItem elderVipSummaryItem = entry.getValue();
			if (null != elderVipSummaryItem.getBeHospitalId()) {
				YrElderBeHospital elderBeHospital = elderBeHospitalMap.get(elderVipSummaryItem.getBeHospitalId());
				if (null != elderBeHospital) {
					elderVipSummaryItem.setBedNumber(elderBeHospital.getBedNumber());
					elderVipSummaryItem.setSubjectRoomName(elderBeHospital.getSubjectRoomName());
					elderVipSummaryItem.setBeNumber(elderBeHospital.getBeNumber());
					elderVipSummaryItem.setBeStatus(elderBeHospital.getBeStatus());

					YrUserVipCard userVipCard = userVipCardMap.get(elderVipSummaryItem.getUserVipCardId());
					elderVipSummaryItem.setCardholder(userVipCard == null ? "" : userVipCard.getName());
				}
			}
			elderVipSummaryItems.add(elderVipSummaryItem);
		}

		Collections.sort(elderVipSummaryItems, new Comparator<YrElderVipSummaryItem>() {

			@Override
			public int compare(YrElderVipSummaryItem o1, YrElderVipSummaryItem o2) {

				return o1.getBedNumber().compareTo(o2.getBedNumber());
			}
		});

		return elderVipSummaryItems;
	}

	private void updayeSubjectRoomSummaryItem(YrElderPayRecord elderPayRecord,
			SubjectRoomSummaryItem subjectRoomSummaryItem) {
		switch (elderPayRecord.getCostType()) {
		// 1基础服务费2护理费3个性服务费4床位费5水费6电费7热水费8院内租赁9代购用品10饭卡充值11rfid卡12欠费补交13手工扣费
		case 1:
			subjectRoomSummaryItem
					.setBaseServiceCost(subjectRoomSummaryItem.getBaseServiceCost() + elderPayRecord.getPayMoney());
			break;
		case 2:
			subjectRoomSummaryItem
					.setNursingCost(subjectRoomSummaryItem.getNursingCost() + elderPayRecord.getPayMoney());
			break;
		case 3:
			subjectRoomSummaryItem.setIndiCost(subjectRoomSummaryItem.getIndiCost() + elderPayRecord.getPayMoney());
			break;
		case 4:
			subjectRoomSummaryItem.setBedCost(subjectRoomSummaryItem.getBedCost() + elderPayRecord.getPayMoney());
			break;
		case 5:
			subjectRoomSummaryItem.setWaterCost(subjectRoomSummaryItem.getWaterCost() + elderPayRecord.getPayMoney());
			break;
		case 6:
			subjectRoomSummaryItem.setEleCost(subjectRoomSummaryItem.getEleCost() + elderPayRecord.getPayMoney());
			break;
		case 7:
			subjectRoomSummaryItem
					.setHotWaterCost(subjectRoomSummaryItem.getHotWaterCost() + elderPayRecord.getPayMoney());
			break;
		case 9:
			subjectRoomSummaryItem
					.setMaterialCost(subjectRoomSummaryItem.getMaterialCost() + elderPayRecord.getPayMoney());
			break;
		case 13:
			switch (subjectRoomSummaryItem.getCostDesc()) {
			case "基础服务费":
				subjectRoomSummaryItem
				.setBaseServiceCost(subjectRoomSummaryItem.getBaseServiceCost() + elderPayRecord.getPayMoney());
				break;
			case "护理费":
				subjectRoomSummaryItem
				.setNursingCost(subjectRoomSummaryItem.getNursingCost() + elderPayRecord.getPayMoney());
			case "个性服务费":
				subjectRoomSummaryItem.setIndiCost(subjectRoomSummaryItem.getIndiCost() + elderPayRecord.getPayMoney());
				return;
			case "床位费":
				subjectRoomSummaryItem.setBedCost(subjectRoomSummaryItem.getBedCost() + elderPayRecord.getPayMoney());
				return;
			case "水费":
				subjectRoomSummaryItem.setWaterCost(subjectRoomSummaryItem.getWaterCost() + elderPayRecord.getPayMoney());
				return;
			case "热水费":
				subjectRoomSummaryItem
				.setHotWaterCost(subjectRoomSummaryItem.getHotWaterCost() + elderPayRecord.getPayMoney());
				return;
			case "材料费":
				subjectRoomSummaryItem
				.setMaterialCost(subjectRoomSummaryItem.getMaterialCost() + elderPayRecord.getPayMoney());
				return;
			case "电费":
				subjectRoomSummaryItem.setEleCost(subjectRoomSummaryItem.getEleCost() + elderPayRecord.getPayMoney());
				return;
			default:
				break;
			}
			subjectRoomSummaryItem.setHandCost(subjectRoomSummaryItem.getHandCost() + elderPayRecord.getPayMoney());
			break;
		default:
			break;
		}
	}

	private class SubjectRoomSummaryList {

		private List<SubjectRoomSummaryItem> subjectRoomSummaryItems;

		public List<SubjectRoomSummaryItem> getSubjectRoomSummaryItems() {
			return subjectRoomSummaryItems;
		}

		public void setSubjectRoomSummaryItems(List<SubjectRoomSummaryItem> subjectRoomSummaryItems) {
			this.subjectRoomSummaryItems = subjectRoomSummaryItems;
		}

	}

	private class YrElderVipSummary {

		private List<YrElderVipSummaryItem> elderVipSummaryItems;

		public List<YrElderVipSummaryItem> getElderVipSummaryItems() {
			return elderVipSummaryItems;
		}

		public void setElderVipSummaryItems(List<YrElderVipSummaryItem> elderVipSummaryItems) {
			this.elderVipSummaryItems = elderVipSummaryItems;
		}

	}

	private class YrElderVipSummaryItem {
		private String beHospitalId;
		private String beNumber; // 住院号
		private String cardholder;// 持卡人
		private String bedNumber;// 床位号
		private String subjectRoomName; // 科室名称
		private String elderName;// 老者姓名
		private Float vipBedCost;
		private Integer beStatus;
		private String userVipCardId;

		public String getUserVipCardId() {
			return userVipCardId;
		}

		public void setUserVipCardId(String userVipCardId) {
			this.userVipCardId = userVipCardId;
		}

		public Integer getBeStatus() {
			return beStatus;
		}

		public void setBeStatus(Integer beStatus) {
			this.beStatus = beStatus;
		}

		public String getBeHospitalId() {
			return beHospitalId;
		}

		public void setBeHospitalId(String beHospitalId) {
			this.beHospitalId = beHospitalId;
		}

		public String getBeNumber() {
			return beNumber;
		}

		public void setBeNumber(String beNumber) {
			this.beNumber = beNumber;
		}

		public String getCardholder() {
			return cardholder;
		}

		public void setCardholder(String cardholder) {
			this.cardholder = cardholder;
		}

		public String getBedNumber() {
			return bedNumber;
		}

		public void setBedNumber(String bedNumber) {
			this.bedNumber = bedNumber;
		}

		public String getSubjectRoomName() {
			return subjectRoomName;
		}

		public void setSubjectRoomName(String subjectRoomName) {
			this.subjectRoomName = subjectRoomName;
		}

		public String getElderName() {
			return elderName;
		}

		public void setElderName(String elderName) {
			this.elderName = elderName;
		}

		public Float getVipBedCost() {
			return vipBedCost;
		}

		public void setVipBedCost(Float vipBedCost) {
			this.vipBedCost = vipBedCost;
		}

	}

	private class SubjectRoomSummaryItem {
		private String beHospitalId;
		private String subjectRoomName; // 科室名称
		private String beNumber; // 住院号
		private String elderName;// 老者姓名
		private String bedNumber;// 床位号
		private Integer beStatus;// 住院状态 0在住1正在出院2已出院
		private Float bedCost; // 床位费
		private Float nursingCost;// 护理费
		private Float baseServiceCost;// 基础服务费
		private Float indiCost;// 个性服务费
		private Float materialCost;// 材料费
		private Float handCost;// 手工扣费
		private Float waterCost;// 水费
		private Float eleCost;// 电费
		private Float hotWaterCost;// 热水费
		private String costDesc; // 扣费描述
		
		public String getCostDesc() {
			return costDesc;
		}

		public void setCostDesc(String costDesc) {
			this.costDesc = costDesc;
		}

		public String getBeHospitalId() {
			return beHospitalId;
		}

		public void setBeHospitalId(String beHospitalId) {
			this.beHospitalId = beHospitalId;
		}

		public String getSubjectRoomName() {
			return subjectRoomName;
		}

		public void setSubjectRoomName(String subjectRoomName) {
			this.subjectRoomName = subjectRoomName;
		}

		public String getBeNumber() {
			return beNumber;
		}

		public void setBeNumber(String beNumber) {
			this.beNumber = beNumber;
		}

		public String getElderName() {
			return elderName;
		}

		public void setElderName(String elderName) {
			this.elderName = elderName;
		}

		public String getBedNumber() {
			return bedNumber;
		}

		public void setBedNumber(String bedNumber) {
			this.bedNumber = bedNumber;
		}

		public Integer getBeStatus() {
			return beStatus;
		}

		public void setBeStatus(Integer beStatus) {
			this.beStatus = beStatus;
		}

		public Float getBedCost() {
			return bedCost;
		}

		public void setBedCost(Float bedCost) {
			this.bedCost = bedCost;
		}

		public Float getNursingCost() {
			return nursingCost;
		}

		public void setNursingCost(Float nursingCost) {
			this.nursingCost = nursingCost;
		}

		public Float getBaseServiceCost() {
			return baseServiceCost;
		}

		public void setBaseServiceCost(Float baseServiceCost) {
			this.baseServiceCost = baseServiceCost;
		}

		public Float getIndiCost() {
			return indiCost;
		}

		public void setIndiCost(Float indiCost) {
			this.indiCost = indiCost;
		}

		public Float getMaterialCost() {
			return materialCost;
		}

		public void setMaterialCost(Float materialCost) {
			this.materialCost = materialCost;
		}

		public Float getHandCost() {
			return handCost;
		}

		public void setHandCost(Float handCost) {
			this.handCost = handCost;
		}

		public Float getWaterCost() {
			return waterCost;
		}

		public void setWaterCost(Float waterCost) {
			this.waterCost = waterCost;
		}

		public Float getEleCost() {
			return eleCost;
		}

		public void setEleCost(Float eleCost) {
			this.eleCost = eleCost;
		}

		public Float getHotWaterCost() {
			return hotWaterCost;
		}

		public void setHotWaterCost(Float hotWaterCost) {
			this.hotWaterCost = hotWaterCost;
		}

	}

	@Override
	public YrElderPayRecordForm toForm(YrElderPayRecord e) throws Exception {
		YrElderPayRecordForm form = ObjectUtils.objectToObject(e, YrElderPayRecordForm.class);
		return form;
	}

	@Override
	public YrElderPayRecord toEntity(YrElderPayRecordForm f) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
